
/**
 * How to read a text file
 * 
 * @author Amrita Mukherjee
 * @version 10/10/2012
 */

import java.io.*; //for file and IOException
import java.util.*; //for scanner and printwriter
public class FileInputExample
{
   
    public static void main(String[] args) throws IOException
    {
        // First lets create a file ("open a file") and a reader
        Scanner reader = new Scanner(new File("myfile.txt"));
        
        //repeat as long as there are more lines in the file
        while(reader.hasNextLine()){
            //read data
            String name = reader.nextLine();  //reads line into name
            String phone = reader.nextLine();  //reads line onto phone
            //Display data
            System.out.println("Name=" + name + ",Phone=" + phone + ".");
        }
        
        //Last, we must close the file(to "unlock" it so others can use it).
        reader.close();
        
        //Let the user know that we're finished.
        System.out.println("Finished reading file.");
    }
}
/*
 * my test session:
 * File written.
Name=Albert Einstein,Phone=(800) 500-1212.
Finished reading file.
*/
